<template>
    <div class="talk">
        <button @click="getTalkList">获取一句话</button>
        <ul>
            <li v-for="item in talkList" :key="item.id">{{item.title}}</li>
        </ul>
    </div>
</template>

<script lang="ts" setup name="LoveTalk">
import {useTalkListStore} from '@/store/loveTalk'
import {storeToRefs} from 'pinia'

const talkStore = useTalkListStore()
const {talkList} = storeToRefs(talkStore)
talkStore.$subscribe((mutate, state)=>{ 
    localStorage.setItem('talkList', JSON.stringify(state.talkList))
})
async function getTalkList() {
    talkStore.addTalk()
}
</script>

<style lang="css" scoped>
.talk {
    margin-top: 30px;
    background-color: orange;
    padding: 10px;
    border-radius: 10px;
    box-shadow: 0 0 10px ;
}
</style>